package com.ogawa.projectcommon.widget

import android.content.Context
import android.graphics.Color
import android.view.View
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.ogawa.projectcommon.R
import com.ogawa.projectcommon.bean.GasBean
import kotlinx.android.synthetic.main.dialog_gas_edit.*

class GasEditDialog(context: Context) : BottomSheetDialog(context, R.style.BottomSheetDialogStyle) {

    init {
        setContentView(R.layout.dialog_gas_edit)
        delegate.findViewById<View>(com.ogawa.base.R.id.design_bottom_sheet)?.setBackgroundColor(
            Color.TRANSPARENT
        )
        tv_no.setOnClickListener { dismiss() }
    }

    fun show(gasBean: GasBean? = null) {
        if (gasBean != null) {
            tr_view.setTime(gasBean.startTime, gasBean.endTime)
            lev_arm.setLev(gasBean.handRank)
            lev_leg.setLev(gasBean.legRank)
            lev_shoulder.setLev(gasBean.shoulderRank)
            lev_seat_side.setLev(gasBean.seatRank)
        }
        show()
    }

    fun isTimeLegal(): Boolean {
        return tr_view.isTimeLegal()
    }

    fun setConfirmClickListener(listener: View.OnClickListener) {
        tv_yes.setOnClickListener(listener)
    }

    fun getTimeRangeView(): TimeRangeView {
        return tr_view
    }

    fun getStartTime(): Int {
        return tr_view.getStartTime()
    }

    fun getEndTime(): Int {
        return tr_view.getEndTime()
    }

    fun getShoulderLev(): Int {
        return lev_shoulder.getLev()
    }

    fun getArmLev(): Int {
        return lev_arm.getLev()
    }

    fun getLegLev(): Int {
        return lev_leg.getLev()
    }

    fun getSeatLev(): Int {
        return lev_seat_side.getLev()
    }
}